The Sound Input Manager provides a number of routines that allow you to begin, pause, resume, and stop recording directly from a sound input device. These low-level routines do not display the sound recording dialog box to the user.
You can use the SPBRecord function to record audio data into memory, either synchronously or asynchronously.
FUNCTION SPBRecord (inParamPtr: SPBPtr; asynchFlag: Boolean):
OSErr;
You specify values and receive return values in the sound input parameter block.
Æ |
|||
´ |
|||
´ |
|||
Æ |
|||
Æ |
|||
Æ |
|||
Æ |
|||
Æ |
|||
¨ |
|||
Æ |
The SPBRecord function starts recording into memory from a device specified in a sound input parameter block. The sound data recorded is stored in the buffer specified by the bufferPtr and bufferLength fields of the parameter block. Recording lasts the longer of the times specified by the count and milliseconds fields of the parameter block, or until the buffer is filled. Recording is asynchronous if the asynchFlag parameter is TRUE and the specified sound input device supports asynchronous recording.
If the bufferPtr field of the parameter block contains NIL , then the count , milliseconds , and bufferLength fields are ignored, and the recording continues indefinitely until you call the SPBStopRecording function. In this case, the audio data is not saved anywhere; this feature is useful only if you want to do something in your interrupt routine and do not want to save the audio data. However, if the recording is synchronous and bufferPtr is NIL , SPBRecord returns the result code siNoBufferSpecified .
The SPBRecord function returns the value that the error field of the parameter block contains when recording finishes.
For an example of the use of the SPBRecord function, see Listing 42 .
You can use the SPBRecordToFile function to record audio data into a file, either synchronously or asynchronously.
FUNCTION SPBRecordToFile (fRefNum: Integer; inParamPtr: SPBPtr;
asynchFlag: Boolean): OSErr;
Æ |
|||
´ |
|||
´ |
|||
Æ |
|||
Æ |
|||
Æ |
|||
¨ |
|||
Æ |
The SPBRecordToFile function starts recording from the specified device into a file. The sound data recorded is simply stored in the file, so it is up to your application to insert whatever headers are needed to play the sound with the Sound Manager. Your application must open the file specified by the fRefNum parameter with write access before calling SPBRecordToFile , and it must eventually close that file.
The fields in the parameter block specified by the inParamPtr parameter are identical to the fields in the parameter block passed to the SPBRecord function, except that the bufferLength and bufferPtr fields are not used. The interruptRoutine field is ignored by SPBRecordToFile because SPBRecordToFile copies data returned by the sound input device driver to disk during the sound input interrupt routine, but you should initialize this field to NIL .
The SPBRecordToFile function writes samples to disk in the same format that they are read in from the sound input device. If compression is enabled, then the samples written to the file are compressed. Multiple channels of sound are interleaved on a sample basis (or, for compressed sound data, on a packet basis). When you are recording 8-bit audio data to an AIFF file, you must set the siTwosComplementOnOff flag to so that the data is stored on disk in the two's-complement format. If you don't store the data in this format, it sounds distorted when you play it back.
If any errors occur during the file writing process, recording is suspended. All File Manager errors are returned through the function's return value if the routine is called synchronously. If the routine is called asynchronously and the completion routine is not NIL , the completion routine is called and is passed a single parameter on the stack that points to the sound input parameter block; any errors are returned in the error field of the sound input parameter block.
The SPBRecordToFile function returns the value that the error field of the parameter block contains when recording finishes.
Because the SPBRecordToFile function moves or purges memory, you should not call it at interrupt time.
You can use the SPBPauseRecording function to pause recording from a sound input device.
FUNCTION SPBPauseRecording (inRefNum: LongInt): OSErr;
The SPBPauseRecording function pauses recording from the device specified by the inRefNum parameter. The recording must be asynchronous for this call to have any effect.
You can use the SPBResumeRecording function to resume recording from a sound input device.
FUNCTION SPBResumeRecording (inRefNum: LongInt): OSErr;
The SPBResumeRecording function resumes recording from the device specified by the inRefNum parameter. Recording on that device must previously have been paused by a call to the SPBPauseRecording function for SPBResumeRecording to have any effect.
You can use the SPBStopRecording function to end a recording from a sound input device.
FUNCTION SPBStopRecording (inRefNum: LongInt): OSErr;
The SPBStopRecording function stops recording from the device specified by the inRefNum parameter. The recording must be asynchronous for SPBStopRecording to have any effect. When you call SPBStopRecording , the sound input completion routine specified in the completionRoutine field of the sound input parameter block is called and the error field of that parameter block is set to abortErr . If you are writing a device driver, you will receive a KillIO Status call. See the section "Writing a Sound Input Device Driver" for more information.
You can use SPBGetRecordingStatus to obtain recording status information about a sound input device.
FUNCTION SPBGetRecordingStatus (inRefNum: LongInt;
VAR recordingStatus: Integer;
VAR meterLevel: Integer;
VAR totalSamplesToRecord:
LongInt;
VAR numberOfSamplesRecorded:
LongInt;
VAR totalMsecsToRecord: LongInt;
VAR numberOfMsecsRecorded:
LongInt):
OSErr;
The SPBGetRecordingStatus function returns, in its second through seventh parameters, information about the recording on the device specified by the inRefNum parameter.
| Previous | Chapter contents | Chapter top | Section top | Next |